<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0"/>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<title>MCU MANAGER</title>
	<%@ include file="/WEB-INF/jsp/common/cssjs2.jsp" %>
	
	<script type="text/javascript">
		var toolbar,grid;
		$(function(){
			toolbar=new dhtmlXToolbarObject("id_bar");
			toolbar.addButton("id_btn_ok",1,"<fmt:message key='btn.ok'/>","<c:url value='/styles/default/images/ok.gif'/>");
			toolbar.addButton("id_btn_cancel",2,"<fmt:message key='btn.cancel'/>","<c:url value='/styles/default/images/unchecked.gif'/>");
			
			toolbar.attachEvent("onClick",function(id){
				if(id=="id_btn_ok"){
					var rowIds=grid.getSelectedRowId();
					if(rowIds==null){
						alert(messages.getMsg("noSelect.tip"));
					}else{
						if("${param.parent}"=="conf"){//parent page refer conference.jsp
							confOKAction(rowIds);
						}
						
						if("${param.parent}"=="main"){//parent page refer main.jsp
							mainOKAction(rowIds);
						}
						
						if("${param.parent}"=="reserve"){// parent page refer confReserve.jsp
							reserveOKAction(rowIds);
						}
					}
				}
				
				if(id=="id_btn_cancel"){
					if("${param.parent}"=="conf"){//parent page refer conference.jsp
						confCancelAction();
					}
					
					if("${param.parent}"=="main"){//parent page refer main.jsp
						mainCancelAction();
					}
					
					if("${param.parent}"=="reserve"){//parent page refer confReserve.jsp
						reserveCancelAction();
					}
				}
			});
			
			grid=new dhtmlXGridObject("id_grid");
			grid.enableMultiselect(true);
			grid.setSkin("${skin}");
			grid.setImagePath("<c:url value='/styles/dhx2/imgs/'/>");
			if("${param.parent}"=="conf"||"${param.parent}"=="reserve"){
				grid.setHeader([
								"<fmt:message key='grid.participant.header.number'/>",
								"<fmt:message key='grid.participant.header.name'/>",
								"<fmt:message key='grid.participant.header.states'/>",
								"<fmt:message key='grid.participant.header.group'/>",
								"<fmt:message key='grid.participant.header.bandwidth'/>",
								"<fmt:message key='grid.participant.header.ip'/>",
								"email"
				   		       ],null,[
		  		                        "text-align:center",
		  		                        "text-align:center",
		  		                        "text-align:center",
		  		                        "text-align:center",
		  		                        "text-align:center",
		  		                        "text-align:center",
		  		                      	"text-align:center"
		  		                      	]);
				grid.setInitWidths("80,100,80,80,80,*,0");
				grid.setColTypes("ro,ro,ro,ro,ro,ro,ro");
				grid.init();
				grid.load("<c:url value='/app/manage/participant/list/json'/>",function(){
					parseTitle();
				},"json");
			}
			if("${param.parent}"=="main"){
				grid.setHeader([
								"<fmt:message key='grid.participant.header.number'/>",
								"<fmt:message key='grid.participant.header.name'/>",
								"<fmt:message key='grid.participant.header.ip'/>",
								"<fmt:message key='grid.participant.header.video'/>",
								"<fmt:message key='grid.participant.header.bandwidth'/>",
								"<fmt:message key='grid.participant.header.states'/>"
				   		       ],null,[
		  		                        "text-align:center",
		  		                        "text-align:center",
		  		                        "text-align:center",
		  		                        "text-align:center",
		  		                        "text-align:center",
		  		                        "text-align:center"
		  		                      	]);
				grid.setInitWidths("80,120,120,70,80,*");
				grid.setColTypes("ro,ro,ro,ch,coro,ro");
				grid.setColumnColor("white,white,white,white,yellow,white");
				var combo=grid.getCombo(4);
			   	$.each([128,192,256,320,384,448,512,640,768,1024,1536,1920,2048,2560,3072,3584,4096],function(){
			   		combo.put(this,this);
			   	});
				grid.init();
				grid.load("<c:url value='/app/manage/participant/invite/list/json'/>",function(){
					parseTitle();
				},"json");
			}
		});
		
		function parseTitle(){
			$("#id_grid").find("span[title^='$']").each(function(){
				this.title=messages.getMsg(this.title.replace("$",""));
			});
		}
		
		function confOKAction(rowIds){
			var pGrid=parent.participantGrid;
			$.each(rowIds.split(","),function(){
				var tid=grid.cells(this,0).getValue();
				var values=[tid,
				            grid.cells(this,1).getValue(),
				            "1",
				            grid.cells(this,5).getValue(),
				            "1",
				            grid.cells(this,4).getValue(),	
				            grid.cells(this,6).getValue(),	//email value
				            grid.cells(this,1).getValue()	//original particiipant name
				            ];
				//alert(values);
				
				if(!pGrid.doesRowExist(tid)){
					pGrid.addRow(tid,values);
					//pGrid.setCellTextStyle(tid,1,"border:1px solid gray;");
					//pGrid.setCellTextStyle(tid,5,"border:1px solid gray;");
				}
			});
			
			parent.closeAddressPopWin();
		}
		
		function confCancelAction(){
			parent.closeAddressPopWin();
		}
		
		function reserveOKAction(rowIds){
			var pGrid=parent.confInfoObj.getPTCGrid();
			$.each(rowIds.split(","),function(){
				var tid=grid.cells(this,0).getValue();
				var values=[tid,
				            grid.cells(this,1).getValue(),
				            "1",
				            grid.cells(this,5).getValue(),
				            "1",
				            grid.cells(this,4).getValue(),	
				            grid.cells(this,6).getValue(),	//email value
				            grid.cells(this,1).getValue()	//original particiipant name
				            ];
				//alert(values);
				
				if(!pGrid.doesRowExist(tid)){
					pGrid.addRow(tid,values);
					//pGrid.setCellTextStyle(tid,1,"border:1px solid gray;");
					//pGrid.setCellTextStyle(tid,5,"border:1px solid gray;");
				}
			});
			
			parent.confInfoObj.closeWin();
		}
		
		function reserveCancelAction(){
			parent.confInfoObj.closeWin();
		}
		
		function mainOKAction(rowIds){
			var ptcs=[];
			
			$.each(rowIds.split(","),function(){
				ptcs.push({
					"p_number":grid.cells(this,0).getValue(),
					"p_ip":grid.cells(this,2).getValue(),
					"p_videoEnabled":grid.cells(this,3).getValue()=="1"?"true":"false",
					"p_bandwidth":grid.cells(this,4).getValue()
				});	
			});
			
			$.ajax({
				url:"<c:url value='/app/manage/conf/control/invite'/>",
				type:"POST",
				data:{
					times:new Date().toString(),
					number:parent.selectedConfNumber,
					participants:$.toJSON(ptcs)
				},
				success:function(data){
					if("<fmt:message key="operation.success"/>" != data)
						alert(data);
					parent.confCtrlViewObj.reloadValues();
					parent.closeWin();
				}
			});
		}
		
		function mainCancelAction(){
			parent.closeWin();
		}
	</script>
	
	<style type="text/css">
	    html, body {
	        width: 100%;
	        height: 100%;
	        margin: 0px;
	        overflow: hidden;
	    }
	</style>
</head>
<body>
	<div id="id_bar"></div>
	<div id="id_grid" style="width:100%;height:95%;"></div>
</body>
</html>